// 做一些数据的存储

/**
 * [saveToLocal description]
 *
 * @param   {[type]}  id     [id description]
 * @param   {[type]}  key    [key description]
 * @param   {[type]}  value  [value description]
 *
 * @return  {[type]}         [return description]
 */
export function saveToLocal(id, key, value) {
  let seller = window.localStorage.__seller__;
  if (!seller) {
    seller = {};
    seller[id] = {};
    seller[id][key] = value;
  } else {
    seller = JSON.parse(seller);
    if (!seller[id]) {
      seller[id] = {};
    }
  }
  seller[id][key] = value;
  window.localStorage.__seller__ = JSON.stringify(seller);
};

/**
 * [loadFromLocal description]
 *
 * @param   {[type]}  id   [id description]
 * @param   {[type]}  key  [key description]
 * @param   {[type]}  def  [def description]
 *
 * @return  {[type]}       [return description]
 */
export function loadFromLocal(id, key, def) {
  let seller = window.localStorage.__seller__;
  if (!seller) {
    return def;
  }
  seller = JSON.parse(seller)[id];
  if (!seller) {
    return def;
  }
  let ret = seller[key];
  return ret || def;
};
